package com.haoxin.ai_course.modules.course.controller;

import org.apache.shiro.authc.AuthenticationException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.haoxin.ai_course.common.annotation.SysLog;
import com.haoxin.ai_course.common.base.AbstractController;
import com.haoxin.ai_course.common.utils.HttpJsonResult;
import com.haoxin.ai_course.modules.course.biz.AcScoreBusiness;
import com.haoxin.ai_course.modules.course.entity.AcScore;
import com.haoxin.ai_course.modules.course.entity.PO.AcScorePO;
import com.haoxin.ai_course.modules.course.entity.VO.AcScoreVO;
import com.haoxin.ai_course.modules.course.service.AcScoreService;
import com.haoxin.ai_course.modules.sys.entity.SysUser;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import lombok.extern.log4j.Log4j;
import lombok.extern.log4j.Log4j2;
import ma.glasnost.orika.MapperFacade;

/**
 * 评分表
 * 
 * @author xingxiangguo
 * @email bugcn@qq.com
 * @date 2022-06-06 09:44:49
 */
@RestController
@AllArgsConstructor
@RequestMapping("/app/course/acscore")
@Api(value = "api", tags = "app小程序-评分管理")
@Log4j2
public class AcScoreController extends AbstractController {
	private final AcScoreService acScoreService;
	
	MapperFacade mapperFacade;
	@Autowired
	AcScoreBusiness acScoreBusiness;
	/**
	 * 信息
	 */
	@SysLog("根据评分类型获取评分记录")
	 @ApiOperation("根据评分类型获取评分记录")
	@GetMapping("/info")
	public HttpJsonResult<AcScoreVO> info(
			@ApiParam("评分类型 1、作业汇总星得分 2知识技能星得分 3 愉悦进度得分 4专注进度得分 5 信心进度得分") @RequestParam("scoreType") Integer scoreType,
			@ApiParam("课程id") @RequestParam("courseId") Integer courseId) {
		
		HttpJsonResult<AcScoreVO> result = new HttpJsonResult<AcScoreVO>();
		try {
			result = acScoreBusiness.getScoreInfo(getUserId(), courseId, scoreType);
		} catch (Exception e) {
			e.printStackTrace();
			result.setMsg("修改评分失败，原因：获取评分发生异常！");
		}
		return result;
	}

	/**
	 * 新增评分表
	 */
	@SysLog("新增评分记录")
	 @ApiOperation("新增评分记录")
	@PostMapping("/save")
	public HttpJsonResult<AcScoreVO> save(@RequestBody AcScorePO acScorePO) {
		
		HttpJsonResult<AcScoreVO>  result = new HttpJsonResult<AcScoreVO> ();
		SysUser user =  getUser();
		try {
			result = acScoreBusiness.save(acScorePO, user.getUserId(), user.getMobile());
		} catch (AuthenticationException e) {
			e.printStackTrace();
			result.setMsg("修改评分失败，原因：修改评分时发生异常,错误信息："+e.getMessage());
		}
		return result;
	}
	public static void main(String[] args) {
		Long a = System.currentTimeMillis()-285048500;
		long b = System.currentTimeMillis();
		System.out.println(a);
		System.out.println(b);
	}
}
